package o;

import android.os.Build.VERSION;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater.Factory;
import android.view.LayoutInflater.Factory2;
import androidx.annotation.NonNull;
import java.lang.reflect.Field;

public final class LayoutInflaterCompatHC {
    private static Field mFeild;
    private static boolean hasReflect;

    private static void setFactory2(LayoutInflater layoutInflater, Factory2 factory2) {
        if (!hasReflect) {
            try {
                mFeild = LayoutInflater.class.getDeclaredField("mFactory2");
                mFeild.setAccessible(true);
            } catch (Throwable e) {
                Log.e("LayoutInflaterCompatHC", "forceSetFactory2 Could not find field 'mFactory2' on class " + LayoutInflater.class.getName() + "; inflation may have unexpected results.", e);
            }
            hasReflect = true;
        }
        if (mFeild != null) {
            try {
                mFeild.set(layoutInflater, factory2);
            } catch (Throwable e2) {
                Log.e("LayoutInflaterCompatHC", "forceSetFactory2 could not set the Factory2 on LayoutInflater " + layoutInflater + "; inflation may have unexpected results.", e2);
            }
        }
    }

    public static void setLayoutInfaltorFactory2(@NonNull LayoutInflater layoutInflater, @NonNull Factory2 factory2) {
        layoutInflater.setFactory2(factory2);
        if (VERSION.SDK_INT < 21) {
            Factory factory = layoutInflater.getFactory();
            if (factory instanceof Factory2) {
                setFactory2(layoutInflater, (Factory2) factory);
            } else {
                setFactory2(layoutInflater, factory2);
            }
        }
    }
}
